<?php
// +----------------------------------------------------------------------
// | 幕小铺
// +----------------------------------------------------------------------
// | 版权所有 2016~2020 幕小铺科技（大连）有限公司
// +----------------------------------------------------------------------
// | 2020/03/14
// +----------------------------------------------------------------------

namespace app\user_center\datacache;
use think\Model;
use think\facade\Debug;
/**
 * 用户统计 缓存层
 * @package app\user_center\model
 */
class UcMemberCount{

    /**
     * 查询数据
     * @param int $uid 用户id
     * @author jason wang <120907037@qq.com>
     * @return array
     */
    public function getInUfoByUid($uid){
        $map = [];
        $map['uid'] = $uid;
        $info = model('user_center/UcMemberCount', 'model\user') ->where($map) -> cache('member_count_by_uid', 60*60*24) -> find()->toArray();
        if(!empty($info)){
            return array_out(200, 'success', $info);
        }else{
            return array_out(-1001, 'error');
        }
    }

    /**
     * 获取热度排行榜 
     * @param int $uid 用户id
     * @author jason wang <120907037@qq.com>
     * @return array
     */
    public function getHotRankList($uid, $num = 10){
        
        $list = model('user_center/UcMemberCount', 'model\user')->withJoin('getMember', 'LEFT') -> order('hot_num desc') ->cache('getHotRankList', 60*60*24)->limit(1000) -> select();
        
        /* 排行榜去除已关注过得人 */
        $rel_list = [];
        foreach ($list as $key => $value) {
            //查询是否已经关注过
            if($uid > 0){
                $rel = model('user_center/UcMemberFollow', 'model\user') -> getDataByFollow($uid, $value -> uid);
                if($rel['code'] == 200 || $uid == $value->uid) continue;//关注过 和 自己 过滤掉
                
            }
            
            $userinfo =controller('user_center/Userlogic', 'logic\user') -> get_user_info($uid, $value['uid']);
            $rel_list[] = $userinfo['data'];
            
            if(count($rel_list) >= $num){
                break;
            }
        }
  
        return array_out(200, 'success', $rel_list);
        
    }
    
    
}
